package com.rain.rainspringboot3.encryption.service;

import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Description: 缓存服务
 * @Author: Rain
 * @Date: 2023/10/26 15:05
 **/
@Service
@AllArgsConstructor
public class CacheService {

    private final RedisTemplate<String, Object> redisTemplate;

    public void saveString(String cacheKey, String plainText, long expire, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(cacheKey, plainText, expire, timeUnit);
    }

    public String getString(String cacheKey) {
        return (String) redisTemplate.opsForValue().get(cacheKey);
    }
}
